########################################
### LOCKING DOWN VIOLENCE,INVITATION ###
###      Brancati, Birnir, Idlbi     ###
########################################

install.packages("scales")
install.packages("ggthemes")

library(ggplot2)
library(tidyverse)
library(readxl)
library(haven)

######################################
## Table 2: Population Interaction  ##
######################################

emoV1<-read.csv("~/Dropbox/LockingDownViolence/Graphs/CurfewsPop.csv", header=TRUE, sep=",")
emoV2<-read.csv("~/Dropbox/LockingDownViolence/Graphs/CurfewsPopNocurfews.csv", header=TRUE, sep=",")
emoV3<-read.csv("~/Dropbox/LockingDownViolence/Graphs/CurfewsPopNonISIScurfews.csv", header=TRUE, sep=",")


#All Values##
F1 <- ggplot() +
  geom_point(data = emoV1, aes(population, zhat1)) + 
  theme_bw()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_y_continuous(name="\n number of violent events", breaks=seq(0, 5, by=1), labels=c("0", "1", "2", "3", "4", "5")) +
  scale_x_continuous(name="\n population (in thousands)", breaks=seq(500000,9500000, by=1000000), labels=c("500", "1500", "2500", "3500", "4500", "5500", "6500", "7500", "8500", "9500")) + 
  xlab("population (in thousands)") +
  ylab("number of events") 
print(F1)   

#No Curfews##
F2 <- ggplot() +
  geom_point(data = emoV2, aes(population, zhat1)) + 
  theme_bw()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_y_continuous(name="\n number of violent events", breaks=seq(0, 5, by=1), labels=c("0", "1", "2", "3", "4", "5")) +
  scale_x_continuous(name="\n population (in thousands)", breaks=seq(500000,9500000, by=1000000), labels=c("500", "1500", "2500", "3500", "4500", "5500", "6500", "7500", "8500", "9500")) + 
  xlab("population (in thousands)") +
  ylab("number of events") 
print(F2)  
  
#NonISIS Curfews##
F3 <- ggplot() +
  geom_point(data = emoV3, aes(population, zhat1)) + 
  theme_bw()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_y_continuous(name="\n number of violent events", breaks=seq(0, 5, by=1), labels=c("0", "1", "2", "3", "4", "5")) +
  scale_x_continuous(name="\n population (in thousands)", breaks=seq(500000,9500000, by=1000000), labels=c("500", "1500", "2500", "3500", "4500", "5500", "6500", "7500", "8500", "9500")) + 
  xlab("population (in thousands)") +
  ylab("number of events") 
print(F3)  

################################
## Table 2: Base Interaction  ##
################################

pmoV2<-read.csv("~/Dropbox/LockingDownViolence/Graphs/TravelBansBase.csv", header=TRUE, sep=",")

F4 <- ggplot() +
  geom_point(data = pmoV2, aes(numberNoBans, zhat_nobans)) + 
  geom_point(data = pmoV2, aes(numberNonISIS, zhat_nonISIS)) + 
    annotate("text", x = 1.5, y=-0.5, label = "No Travel Bans", vjust =
             1.5, size=3, fontface =1) +
    annotate("text", x = 3.5, y=-0.5, label = "Non-ISIS Travel Bans", vjust =
             1.5, size=3, fontface =1) +             
  theme_bw()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_y_continuous(name="\n number of violent events", breaks=seq(0,5, by=1), labels=c("0", "1", "2", "3", "4", "5")) +
  scale_x_continuous(name="", breaks=seq(1,4, by=1), labels=c("non-base", "base", "non-base", "base")) + 
  xlab("") +
  ylab("number of violent events") 
  
 print(F4)  

        
  